package hcQuest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Panel;

import javax.swing.JButton;
import javax.swing.JLabel;

import webExperiment.SelectionQuestion;

class HCQ_QuestionPanel extends Panel {
    /**
	 * 
	 */
    private static final long serialVersionUID = 1L; // v2

    private static final Color BGCOLOR = Color.WHITE; // new Color(255, 254,
    // 218);
    private static final int LabelWidth = 40;

    public static final int theNoChoices = 3;

    private SelectionQuestion sq1, sq2, sq3, sq4, sq5, sq6, sq7, sq8, sq9;

    protected JButton okButton = new JButton();
    // private JTextArea TextArea = new JTextArea();
    private JLabel label2 = new JLabel();
    private int noQuestions = 0;
    private String dataDelim;

    public HCQ_QuestionPanel(String btnText, String dataDelimiter) {
	dataDelim = dataDelimiter;
	this.setVisible(false);
	this.setSize(600, 500);
	this.setLocation(0, 0);
	// this.setBackground(Color.white);
	label2.setFont(new Font("Arial", Font.ITALIC + Font.BOLD, 12));
	okButton.setText(btnText);
	okButton.setPreferredSize(new Dimension(160, 30));

	SelectionQuestion.QuestWidth = 280;
	SelectionQuestion.Width = 500;
	SelectionQuestion.Defautheight = 40;
	SelectionQuestion.HGap = 1;
	sq1 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq2 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq3 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq4 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq5 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq6 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq7 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq8 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);
	sq9 = new SelectionQuestion(theNoChoices, BGCOLOR, LabelWidth, true);

    }

    public void setInfoText(String txt) {
	label2.setText(txt);
    }

    public void addHandQuestions(int theNoQuestions) {
	noQuestions = theNoQuestions;
	this.removeAll();
	this.setLayout(new FlowLayout(FlowLayout.CENTER, 50, 10));
	for (int x = 1; x <= noQuestions; x++) {
	    SelectionQuestion sq = setQuestionText(x, "Question not defined!",
		    "??", "??", "??");
	    if (sq != null)
		add(sq);
	}
	add(okButton);
	add(label2);
    }

    public SelectionQuestion setQuestionText(int questionID, String question,
	    String label1, String label2, String label3) {
	SelectionQuestion sq = getQuestion(questionID);
	if (sq != null) {
	    sq.setQuestion(question);
	    sq.setSelectionLabels(1, label1);
	    sq.setSelectionLabels(2, label2);
	    sq.setSelectionLabels(3, label3);
	}
	return sq;
    }

    private SelectionQuestion getQuestion(int questionID) {
	if (questionID == 1)
	    return sq1;
	else if (questionID == 2)
	    return sq2;
	else if (questionID == 3)
	    return sq3;
	else if (questionID == 4)
	    return sq4;
	else if (questionID == 5)
	    return sq5;
	else if (questionID == 6)
	    return sq6;
	else if (questionID == 7)
	    return sq7;
	else if (questionID == 8)
	    return sq8;
	else if (questionID == 9)
	    return sq9;
	else
	    return null;
    }

    public String getAnswers() {
	String a = "";
	int tmp;
	for (int x = 1; x <= noQuestions; x++) {
	    tmp = getQuestion(x).getSelectedItem();
	    if (x > 1)
		a = a + dataDelim;
	    a = a + Integer.toString(tmp);
	}
	return a;
    }
}// class

